package com.it.gw.modules.water.activity

import android.view.View
import androidx.activity.viewModels
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.viewpager2.widget.ViewPager2
import com.it.common.view.CommonViewPager2Adapter
import com.it.gw.R
import com.it.gw.base.BaseActivity
import com.it.gw.databinding.ActivityReservoirUploadBinding
import com.it.gw.modules.water.fragment.ReservoirSeeFragment
import com.it.gw.modules.water.fragment.ReservoirUploadFragment
import com.it.gw.modules.water.viewmodel.WaterViewModel


//水库报汛
class ReservoirUploadActivity : BaseActivity<ActivityReservoirUploadBinding>() {
    private val fragmentList by lazy { mutableListOf<Fragment>() }
     val waterViewModel by viewModels<WaterViewModel>()
    companion object {
        const val TAG = "ReservoirUploadActivity"
    }


    override fun initObserver() {

    }


    override fun initListener() {
        binding.rlUpload.setOnClickListener {
            binding.vContent.currentItem = 0


        }
        binding.rlSee.setOnClickListener {
            binding.vContent.currentItem = 1

        }
        binding.vContent.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                if (position == 0) {
                    binding.tvUpload.setTextColor(
                        ContextCompat.getColor(
                            this@ReservoirUploadActivity,
                            R.color.color_0F6AF8
                        )
                    )
                    binding.vLine1.visibility = View.VISIBLE
                    binding.tvSee.setTextColor(
                        ContextCompat.getColor(
                            this@ReservoirUploadActivity,
                            R.color.color_999999
                        )
                    )
                    binding.vLine2.visibility = View.INVISIBLE
                    setTitle(
                        title = R.string.str_reservoir_upload,
                        isBack = true,

                        )
                } else {
                    binding.tvSee.setTextColor(
                        ContextCompat.getColor(
                            this@ReservoirUploadActivity,
                            R.color.color_0F6AF8
                        )
                    )
                    binding.vLine2.visibility = View.VISIBLE
                    binding.tvUpload.setTextColor(
                        ContextCompat.getColor(
                            this@ReservoirUploadActivity,
                            R.color.color_999999
                        )
                    )
                    binding.vLine1.visibility = View.INVISIBLE
                    setTitle(
                        title = R.string.str_reservoir_upload,
                        isBack = true,
                        tvRightRes1 = R.string.str_select,
                        tvRight1Action = {
                            reservoirSeeFragment.searchView()
                        }
                    )
                }
            }

        })

    }


    override fun initData() {

    }

    val reservoirUploadFragment by lazy { ReservoirUploadFragment() }
    val reservoirSeeFragment by lazy { ReservoirSeeFragment() }
    override fun initView() {
        setTitle(
            title = R.string.str_reservoir_upload,
            isBack = true,

            )
        fragmentList.add(reservoirUploadFragment)
        fragmentList.add(reservoirSeeFragment)

        binding.vContent.adapter =
            CommonViewPager2Adapter(supportFragmentManager, lifecycle, fragmentList)
        binding.vContent.offscreenPageLimit = 2

    }


    override fun setContentView() {
        binding = ActivityReservoirUploadBinding.inflate(layoutInflater)
        setContentView(binding.root)
    }


}